package com.tutou.ikgroup.mapper;

import com.tutou.ikgroup.pojo.dto.FriendDTO;
import com.tutou.ikgroup.pojo.po.Friend;
import com.tutou.ikuser.pojo.po.User;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface ChatFriendMapper {

    @Select("select user_id from friends where friend_id=#{userId} and status=1")
    List<String> getFriendRequest(String userId);

    List<Friend> getFriendAllRequest(String userId);

    @Select("select count(*) from friends where user_id=#{senderId} and friend_id=#{receiverId}")
    int judgeFriendAdd(FriendDTO friendDTO);

    @Insert("insert into friends (user_id, friend_id, message) VALUES (#{senderId},#{receiverId},#{message} )")
    void saveFriend(FriendDTO friendDTO);

    @Insert("insert into friends (user_id, friend_id,status,message) VALUES (#{senderId},#{receiverId},#{status},#{message})")
    void saveFriend2(FriendDTO friendDTO);

    @Update("update friends set status=#{status} where friend_id=${receiverId} and user_id=#{senderId}")
    void passOrRejectFriend(FriendDTO friendDTO);

    @Update("update friends set status=#{status} where friend_id=${senderId} and user_id=#{receiverId}")
    void passOrRejectFriend2(FriendDTO friendDTO);

    List<HashMap<String, String>> getFriendRequestNameByUserId(List<String> userIds);

    @Update("update friends set status=2 where status=1")
    void UpdateOfflineFriendRequestStatus();

    @Select("select status from friends where user_id=#{receiverId} and friend_id=#{senderId}")
    String getFriend(FriendDTO friendDTO);

    List<String> getNewFriendPassOrReject(String userId);

    List<Friend> getFriendList(String userId);

    @Delete("delete from friends where (user_id=#{senderId} and friend_id=#{receiverId}) " +
            "or user_id=#{receiverId} and friend_id=#{senderId}")
    void deleteFriend(FriendDTO friendDTO);

    @Delete("delete from messages where (sender_id=#{senderId} and receiver_id=#{receiverId}) " +
            "or sender_id=#{receiverId} and receiver_id=#{senderId}")
    void deleteFriendMessage(FriendDTO friendDTO);
}
